package com.example.shop_2302.adapter

import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.Order
import com.example.base.entity.OrderInfo
import com.example.shop_2302.R
import com.example.shop_2302.utils.GlideUtils

class OrderAdapter:BaseQuickAdapter<Order,BaseViewHolder> (R.layout.item_order){
    override fun convert(holder: BaseViewHolder, item: Order) {
        holder.setText(R.id.order_time,item.createTime)
        holder.setText(R.id.order_status,item.orderStatus)
        holder.setText(R.id.order_total,"共${item.totalNum}种商品，合计金额${item.payPrice}元")
        //rv
        val rv = holder.getView<RecyclerView>(R.id.order_rv)
        //
        val orderChildAdapter = OrderChildAdapter()
        orderChildAdapter.data.addAll(item.orderInfoList)
        rv.adapter = orderChildAdapter
        rv.layoutManager = LinearLayoutManager(context)
        //当订单状态不同时，下方按钮文字不同
        if(item.orderStatus=="待支付"){
            holder.getView<TextView>(R.id.order_pay).text = "立即付款"
            holder.getView<TextView>(R.id.order_cancel).text = "取消订单"
        }else if(item.orderStatus=="待发货"){
            holder.getView<TextView>(R.id.order_pay).text = "催商家发货"
            holder.getView<TextView>(R.id.order_cancel).text = "申请退款"
        }else if(item.orderStatus=="售后"){
            holder.getView<TextView>(R.id.order_pay).text = "查看进度"
            holder.getView<TextView>(R.id.order_cancel).text = "申请客服介入"
        }
    }
}

class OrderChildAdapter:BaseQuickAdapter<OrderInfo,BaseViewHolder>(R.layout.item_order_child){
    override fun convert(holder: BaseViewHolder, item: OrderInfo) {
        GlideUtils.loadNormal(context,item.image,holder.getView(R.id.preorder_iv))
        holder.setText(R.id.preorder_storename,item.storeName)
        holder.setText(R.id.preorder_num,item.cartNum.toString())
        holder.setText(R.id.preorder_price,item.price)
        holder.setText(R.id.preorder_sku,"")
    }

}